#include "QuantizationMatrix.h"

QuantizationMatrix::QuantizationMatrix()
{
	_quantizationMatrix = 0;
	_size = 0;
	_columnLength = 0;
}


QuantizationMatrix::~QuantizationMatrix()
{
	delete[] _quantizationMatrix;
}

QuantizationMatrix::QuantizationMatrix(int columnLength)
{
    _columnLength = columnLength;
    _size = columnLength*columnLength;
    _quantizationMatrix = new int[_size];
    for(int i=0; i < _size; ++i)
        _quantizationMatrix[i] = 1;
}

QuantizationMatrix::QuantizationMatrix(const QuantizationMatrix &qm)
{
    _columnLength = qm.columnLength();
    _size = qm.size();
    _quantizationMatrix = new int[_size];
    for(int i=0; i < _size; ++i )
        _quantizationMatrix[i] = qm[i];
}

QuantizationMatrix& QuantizationMatrix::operator=( const QuantizationMatrix q )
{
	_size = q.size();
	_columnLength = q.columnLength();
	if(_quantizationMatrix != 0)
		delete[] _quantizationMatrix;

	_quantizationMatrix = new int[_size];

	for(int i = 0; i < _size; ++i)
		_quantizationMatrix[i] = q[i];

	return *this;
}

void QuantizationMatrix::setMatrix(int *matrix)
{
    for(int i=0; i < _size; ++i)
        _quantizationMatrix[i] = matrix[i];
}

void QuantizationMatrix::setMatrixRowMajor(int *matrix)
{
    for(int i=0; i < _columnLength; ++i)
        for(int j=0; j < _columnLength; ++j)
            _quantizationMatrix[i*_columnLength+j] = matrix[j*_columnLength+i];
}

void QuantizationMatrix::setMatrix(uint8_t *matrix)
{
    for(int i=0; i < _size; ++i)
        _quantizationMatrix[i] = (int)matrix[i];
}
